package com.super1;

/**
 * Time    : 2023/3/18 15:12
 * Author  : 王摇摆
 * FileName: Test1.java
 * Software: IntelliJ IDEA 2020.2.2
 * Blog    ：https://blog.csdn.net/weixin_44943389?type=blog
 */

public class Test1 {

    public static void main(String[] args) {
        Cat2 c1 = new Cat2("小猫",3);
        System.out.println("名字：" + c1.getName());
        System.out.println("年龄：" + c1.getAge());
    }
}

//父类，Animal类
class Animal2 {
    //私有属性：名字
    private String name;

    //setter and getter
    public void setName(String name) {
        this.name = name;
    }
    public String getName() {
        return name;
    }

    //构造函数
    public Animal2() {

    }
    public Animal2(String name) {
        this.name = name;
    }
}

//子类，Cat类
class Cat2 extends Animal2 {
    //私有字段：年龄
    private int age;

    //setter and getter
    public void setAge(int age) {
        this.age = age;
    }
    public int getAge() {
        return age;
    }

    //构造函数
    public Cat2() {

    }
    public Cat2(String name,int age) {
//        this.name=name;//父类属性name是private的，在子类中无法访问
//        setName(name);//可以完成赋值，不建议这么做
        super("小猫");
        this.age = age;
    }
}
